import time
from machine import SPI, Pin
from driver import st7789_spi
from lib.easydisplay import EasyDisplay


spi = SPI(1, baudrate=20000000, polarity=0, phase=0, sck=Pin(10), mosi=Pin(8))
dp = st7789_spi.ST7789(width=320, height=240, spi=spi, cs=2, dc=4, res=6, rotate=2, bl=1,invert=False, rgb=False)

sm= EasyDisplay(display=dp, font="/text_full_16px_2312.v3.bmf", show=True, color=0xFFFF, auto_wrap=True, clear=True,color_type="RGB565")
bg = EasyDisplay(display=dp, font="/text_full_24px_2312.v3.bmf", show=True, color=0xFFFF, auto_wrap=True, clear=True,color_type="RGB565")
bg.clear()

class seal(object):
    def __init__(self,info,sm=sm,bg=bg):
        self.sm=sm
        self.bg=bg
        self.info=info
        self.n=0
        self.print_time(info['time'])
        self.print_dep(info['dep'])
        self.print_type(info['type'])
        self.print_seal(info['seal'])
        self.print_name(info['name'])
        self.print_info(info['info'])
        self.print_file(info['file'])
    def print_time(self,data):
        sm=self.sm
        sm.text(str(data), 240, 0,clear=False)
        
    def print_dep(self,data):
        sm=self.sm
        sm.text(str(data), 150, 0,clear=False)

    def print_type(self,data):
        sm=self.bg
        sm.text(str(data), 0, 0,clear=False,color=0xF11)

    def print_seal(self,data):
        sm=self.sm
        sm.text(str(data), 0, 26,clear=False,color=0xFAA)
        self.n=(len(str(data))//13)+1
    def print_name(self,data):
        sm=self.sm
        n=self.n
        sm.text(str(data), 0, 24*n,clear=False,color=0x0BA)
        self.n=(len(str(data))//21)+self.n+1
    def print_info(self,data):
        sm=self.sm
        n=self.n
        sm.text(str(data), 0, 24+16*n,clear=False)
        self.n=(len(str(data))//21)+self.n+1
    def print_file(self,data):
        sm=self.sm
        n=self.n
        sm.text(str(data), 0, 24+16*n,clear=False,color=0xF0F)
    


info={
        "time":"2024-1-31",
        "dep":"综合管理部",
        "type":"盖章类型一",
        "name":"吴冬旭 沈永锋 沈琦:2月1日一天",
        "info":"我单位经过自查，本月未发现违反网络安全规定的相关行为，未发生工作泄密情况。",
        "seal":"苏州吴江经济技术开发区发展集团有限公司",
        "file":"我问问sdasdasd萨达奥术大师多阿萨德而我二而非沃尔沃二翁 x1\n对对对 x2\n我问问 x3\n我问问 x4\n我问问 x5\n我问问 x6\n我问问 x7\n我问问 x8\n我问问 x9\n我问问 x10\n"
    }
k=seal(info)

